package com.service.dialtest.service.impl;

import com.service.dialtest.dao.WebUserDao;
import com.service.dialtest.dto.DialTestDto;
import com.service.dialtest.dto.UserShopDto;
import com.service.dialtest.entity.WebUserInfo;
import com.service.dialtest.model.DialingMetric;
import com.service.dialtest.service.DialTestService;
import com.service.config.utils.ModelMapperUtil;
import com.service.config.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Description:
 * @Author: hjl
 * @Date: 2021/10/28 14:59
 */
@Service
@Slf4j
public class DialTestServiceImpl implements DialTestService {
    @Resource
    private RedisUtil redisUtil;
    @Autowired
    private WebUserDao userDao;

    @Override
    public Object queryDayaOfDialTest(String userId) {
        List<DialTestDto> list = ModelMapperUtil.strictMapList(redisUtil.getList1(userId.concat("_dialTest")), DialTestDto.class);
        WebUserInfo webUserInfo = userDao.queryById(userId);
        UserShopDto userShopDto = ModelMapperUtil.strictMap(webUserInfo, UserShopDto.class);
        if (list.size() > 0) {
            AtomicReference<Integer> sumCount = new AtomicReference<>(0);
            Map map = new HashMap();
            map.put("sumCount", sumCount);
            map.put("dialTest", list);
            map.put("userShop",userShopDto);
            return map;
        } else {
            return null;
        }
    }
}
